package com.yimils.core.common.exception;

import com.yimils.core.common.dto.RspBase;
import org.apache.shiro.authc.AuthenticationException;
import org.apache.shiro.authz.AuthorizationException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;

@RestControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = AuthenticationException.class)
    public RspBase AuthenticationExceptionHandler(Exception ex) {
        return RspBase.ERROR(405, "用户名或者密码错误");
    }

    @ExceptionHandler(value = AuthorizationException.class)
    public RspBase AuthorizationExceptionExceptionHandler(Exception ex) {
        return RspBase.ERROR(403, "没有操作权限");
    }

    @ExceptionHandler(value = SQLIntegrityConstraintViolationException.class)
    public RspBase SQLIntegrityConstraintViolationExceptionHandler(Exception ex) {
        return RspBase.ERROR(400, "重复操作");
    }

}
